package com.kk.crowd.service.impl;

import com.kk.crowd.entity.po.MemberPO;
import com.kk.crowd.entity.po.MemberPOExample;
import com.kk.crowd.mapper.MemberPOMapper;
import com.kk.crowd.service.api.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

// 在类上使用@Transactional(readOnly = true)针对查询操作设置事务属性
// 人话：只读
@Transactional(readOnly = true)
@Service
public class MemberServiceImpl  implements MemberService {

    @Autowired
    private MemberPOMapper memberPOMapper;

    public MemberPO getMemberPOByLoginAcct(String loginacct) {

        // 1.创建 Example 对象
        MemberPOExample example = new MemberPOExample ( );

        // 2.创建 Criteria 对象
        MemberPOExample.Criteria criteria = example.createCriteria ( );

        // 3.封装查询条件
        criteria.andOginacctEqualTo (loginacct);  //这边字段定义错误 oginacct 就是 loginacct

        // 4.执行查询
        List<MemberPO> memberPOList = memberPOMapper.selectByExample (example);

        return memberPOList.get (0);
    }


    // 对方法取消只读，设置事务传播行为  readOnly = false(默认是false)
    @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class,readOnly = false)
    public void saveMember(MemberPO memberPO) {
        memberPOMapper.insertSelective (memberPO);
    }




}
